using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.Serialization;
using System.Collections.Concurrent;
using System.ServiceModel;
using GZ.Modular.Log;
using GZ.Modular.Redis;
using GZ.Modular.Database;
using MongoDB.Driver;
using Dapper;
using System.Configuration;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using GZ.DB.Entity.wcs_yb;
using GZ.DB.IRepository.wcs_yb;
using GZ.DB.Repository.wcs_yb;
using GZ.Common.Data;
using Newtonsoft.Json;
using System.Security.Cryptography;
using System.Net;
using System.Threading;
using System.Globalization;
using System.IO.Ports;
using System.Drawing;
namespace GZ.Projects.WCS_YB
{
	#region 设备通信
	/// <summary>
	/// 设备通信
	/// </summary>
	public class Device
	{
		public GZ.Device.PLC.PlcBase MEM=null;
		public GZ.Device.PLC.PlcBase CV01=null;
		public GZ.Device.PLC.PlcBase TC01=null;
		public GZ.Device.PLC.PlcBase CV01_INFO=null;
		private static Device device;
		private static readonly object locker = new object();
		public static Device CreateInstance()
        {
            if (device == null)
            {
                lock (locker)
				{
					device = new Device();
				}
            }
			return device;
        }
		private Device()
		{
			MEM = GZ.Device.PLC.PlcFactory.CreateInstanceByFile
			(
				System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", "MEM"),
				null,null,null
			);
			CV01 = GZ.Device.PLC.PlcFactory.CreateInstanceByFile
			(
				System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", "CV01"),
				null,null,null
			);
			TC01 = GZ.Device.PLC.PlcFactory.CreateInstanceByFile
			(
				System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", "TC01"),
				null,null,null
			);
			CV01_INFO = GZ.Device.PLC.PlcFactory.CreateInstanceByFile
			(
				System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", "CV01_INFO"),
				null,null,null
			);
			if(System.Configuration.ConfigurationManager.AppSettings["AutoRunPLC"]=="1")
			{
				if(MEM!=null){MEM.Run();}
				if(CV01!=null){CV01.Run();}
				if(TC01!=null){TC01.Run();}
				if(CV01_INFO!=null){CV01_INFO.Run();}
			}
        }
	}
	#endregion
	
	#region 简单PLC
		
	/// <summary>
	/// PLC变量组
	/// </summary>
	public class EasyPLC
	{
		private static EasyPLC easyPLC;
		private static readonly object locker = new object();
		public static EasyPLC CreateInstance()
        {
            if (easyPLC == null)
            {
                lock (locker)
				{
					easyPLC = new EasyPLC();
				}
            }
			return easyPLC;
        }
		private EasyPLC()
        {

        }
		
		#region MEM
		public _MEM MEM = new _MEM();
		/// <summary>
		/// 记录mem的值
		/// </summary>		
		public class _MEM
		{
			public _TC01_INFO TC01_INFO = new _TC01_INFO();
			/// <summary>
			/// 
			/// </summary>	
			public class _TC01_INFO
			{
				public string TC01_DeviceTaskNo = "";
				public string TC01_ContNo = "";
				public string TC01_CurPos = "";
				public string TC01_ToPos = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
		}
		#endregion
		
		#region CV01
		public _CV01 CV01 = new _CV01();
		/// <summary>
		/// 东侧
		/// </summary>		
		public class _CV01
		{
			public _SENDTASK_101011 SENDTASK_101011 = new _SENDTASK_101011();
			/// <summary>
			/// 
			/// </summary>	
			public class _SENDTASK_101011
			{
				public string WCS_FLOW_101011 = "";
				public string WCS_TASKNO_101011 = "";
				public string WCS_CONTTYPE_101011 = "";
				public string WCS_CONTNO_101011 = "";
				public string WCS_SENT_101011 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _SENDTASK_101012 SENDTASK_101012 = new _SENDTASK_101012();
			/// <summary>
			/// 
			/// </summary>	
			public class _SENDTASK_101012
			{
				public string WCS_TASKNO_101012 = "";
				public string WCS_CONTTYPE_101012 = "";
				public string WCS_CONTNO_101012 = "";
				public string WCS_SENT_101012 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _OUTTASK_101012 OUTTASK_101012 = new _OUTTASK_101012();
			/// <summary>
			/// 
			/// </summary>	
			public class _OUTTASK_101012
			{
				public string WCS_OUTSENT_101012 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _REACH_101011 REACH_101011 = new _REACH_101011();
			/// <summary>
			/// 
			/// </summary>	
			public class _REACH_101011
			{
				public string WCS_FLOW_101011 = "";
				public string WCS_REACHSENT_101011 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _OUTTASK_101010 OUTTASK_101010 = new _OUTTASK_101010();
			/// <summary>
			/// 
			/// </summary>	
			public class _OUTTASK_101010
			{
				public string WCS_OUTSENT_101010 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _BACK_101010 BACK_101010 = new _BACK_101010();
			/// <summary>
			/// 
			/// </summary>	
			public class _BACK_101010
			{
				public string WCS_REACHSENTBACK_101010 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _OUTFINISH_101012 OUTFINISH_101012 = new _OUTFINISH_101012();
			/// <summary>
			/// 
			/// </summary>	
			public class _OUTFINISH_101012
			{
				public string WCS_OUTFINISHSENT_101012 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _INFINISH_101010 INFINISH_101010 = new _INFINISH_101010();
			/// <summary>
			/// 
			/// </summary>	
			public class _INFINISH_101010
			{
				public string WCS_INFINISHSENT_101010 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _OUTFINISH_101010 OUTFINISH_101010 = new _OUTFINISH_101010();
			/// <summary>
			/// 
			/// </summary>	
			public class _OUTFINISH_101010
			{
				public string WCS_OUTFINISHSENT_101010 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _BACK_101009 BACK_101009 = new _BACK_101009();
			/// <summary>
			/// 
			/// </summary>	
			public class _BACK_101009
			{
				public string WCS_REACHSENTBACK_101009 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _INFINISH_101009 INFINISH_101009 = new _INFINISH_101009();
			/// <summary>
			/// 
			/// </summary>	
			public class _INFINISH_101009
			{
				public string WCS_INFINISHSENT_101009 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _OUTFINISH_101009 OUTFINISH_101009 = new _OUTFINISH_101009();
			/// <summary>
			/// 
			/// </summary>	
			public class _OUTFINISH_101009
			{
				public string WCS_OUTFINISHSENT_101009 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _REACH_101007 REACH_101007 = new _REACH_101007();
			/// <summary>
			/// 
			/// </summary>	
			public class _REACH_101007
			{
				public string WCS_FLOW_101007 = "";
				public string WCS_REACHSENT_101007 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _SENDTASK_101002 SENDTASK_101002 = new _SENDTASK_101002();
			/// <summary>
			/// 
			/// </summary>	
			public class _SENDTASK_101002
			{
				public string WCS_TASKNO_101002 = "";
				public string WCS_CONTTYPE_101002 = "";
				public string WCS_CONTNO_101002 = "";
				public string WCS_SENT_101002 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _REACH_101006 REACH_101006 = new _REACH_101006();
			/// <summary>
			/// 
			/// </summary>	
			public class _REACH_101006
			{
				public string WCS_REACHSENT_101006 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _OUTTASK_101001 OUTTASK_101001 = new _OUTTASK_101001();
			/// <summary>
			/// 
			/// </summary>	
			public class _OUTTASK_101001
			{
				public string WCS_OUTSENT_101001 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _INTASK_101001 INTASK_101001 = new _INTASK_101001();
			/// <summary>
			/// 
			/// </summary>	
			public class _INTASK_101001
			{
				public string WCS_INSENT_101001 = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
		}
		#endregion
		
		#region TC01
		public _TC01 TC01 = new _TC01();
		/// <summary>
		/// 堆垛机
		/// </summary>		
		public class _TC01
		{
			public _StackerFinishSend StackerFinishSend = new _StackerFinishSend();
			/// <summary>
			/// 
			/// </summary>	
			public class _StackerFinishSend
			{
				public string wcs_taskFinishAffirm = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _StackerAffirm StackerAffirm = new _StackerAffirm();
			/// <summary>
			/// 
			/// </summary>	
			public class _StackerAffirm
			{
				public string wcs_taskErrorAffirm = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _SendTask SendTask = new _SendTask();
			/// <summary>
			/// 
			/// </summary>	
			public class _SendTask
			{
				public string wcs_trayType = "";
				public string wcs_startPosX = "";
				public string wcs_startPosY = "";
				public string wcs_startPosZ = "";
				public string wcs_endPosX = "";
				public string wcs_endPosY = "";
				public string wcs_endPosZ = "";
				public string wcs_taskType = "";
				public string wcs_taskNo = "";
				public string wcs_taskExe = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _HeartBeat HeartBeat = new _HeartBeat();
			/// <summary>
			/// 
			/// </summary>	
			public class _HeartBeat
			{
				public string wcs_heartBeat = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
			public _StackDelivery StackDelivery = new _StackDelivery();
			/// <summary>
			/// 
			/// </summary>	
			public class _StackDelivery
			{
				public string wcs_taskInAffirm = "";

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
		}
		#endregion
		
		#region CV01_INFO
		public _CV01_INFO CV01_INFO = new _CV01_INFO();
		/// <summary>
		/// 输送线基础信息
		/// </summary>		
		public class _CV01_INFO
		{
			public _HEARTBEAT HEARTBEAT = new _HEARTBEAT();
			/// <summary>
			/// 
			/// </summary>	
			public class _HEARTBEAT
			{

				public bool Write()
				{
					return Write(null);
				}
				
				public bool Write(string logicNo)
				{
					return true;
				}
			}
		}
		#endregion
		
	}

	#endregion
}